import logging
import pandas as pd

# 命令名称 0
# 结果参数名称 1
# 命令输出参数范围 2
# 输出参数与对象属性的映射信息 3
# 操作结果使能参数 4
# 操作结果表号 5
# 是否参数隐藏 6
# 英文显示名称 7
# 中文显示名称 8
# 表头英文描述 9
# 表头中文描述 10
from commens import dump_to_json


def getExcelData():
    res = {}
    currentMML = None
    filename = '5GMML.xlsx'
    sheet = '命令结果参数'
    df = pd.read_excel(filename,sheet_name=sheet)
    print("从%s中获取到了%d条数据"%(filename,len(df)))
    count = 0
    for row in df.itertuples():
        row = row[1:]
        if count>1:
            if currentMML != row[0]:
                res[row[0]] = []
                logOUTPARAM.debug('●%s'%row[0])
            res[row[0]].append({
                '参数标识':row[1],
                '参数名称':row[8],
                '参数含义':'输出参数',
                '取值范围':row[2],
                '配置原则':'无'
            })
            logOUTPARAM.debug('%s' % row[1])
            currentMML = row[0]
        count += 1
    return res


def main():
    data = getExcelData()
    print('生成了%d条数据'%len(data))
    dump_to_json(data,'OUTPARAM.json')


if __name__ == '__main__':
    logOUTPARAM = logging.getLogger("OUTPARAM")
    logOUTPARAM.setLevel(logging.DEBUG)
    hdOUTPARAM = logging.FileHandler("OUTPARAM.log", mode='w', encoding='utf-8')
    ch = logging.StreamHandler()
    ch.setLevel(logging.INFO)
    hdOUTPARAM.setLevel(logging.DEBUG)
    logOUTPARAM.addHandler(hdOUTPARAM)
    logOUTPARAM.addHandler(ch)
    main()